local DIY = require "packages.diy_utility.diy_utility"

local skel = fk.CreateSkill {
  name = "rmt__xuanjian",
  tags = {DIY.ReadySkill},
}

Fk:loadTranslationTable{
  ["rmt__xuanjian"] = "玄剑",
  [":rmt__xuanjian"] = "蓄势技，你造成/受到伤害后，可以亮出牌堆顶的三张牌并获得其中的伤害牌/非伤害牌。",

  ["#rmt__xuanjian-damage"] = "玄剑：你可以牌堆顶的3张牌，获得其中的伤害牌",
  ["#rmt__xuanjian-nondamage"] = "玄剑：你可以牌堆顶的3张牌，获得其中的非伤害牌",

  ["$rmt__xuanjian1"] = "恨我音灭，怨我血枯，折髓笑去，鬼神诛。",
  ["$rmt__xuanjian2"] = "旦为朝云，暮为行雨。朝朝暮暮，阳台之下。",
}

skel:addEffect(fk.Damage, {
  anim_type = "offensive",
  audio_index = 1,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name) and target == player
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askToSkillInvoke(player, { skill_name = skel.name, prompt = "#rmt__xuanjian-damage" })
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local cards = room:getNCards(3)
    room:moveCardTo(cards, Card.Processing, nil, fk.ReasonJustMove, skel.name, nil, true, player)
    room:delay(800)
    if not player.dead then
      local get = table.filter(cards, function (id)
        return room:getCardArea(id) == Card.Processing and Fk:getCardById(id).is_damage_card
      end)
      if #get > 0 then
        room:obtainCard(player, get, true, fk.ReasonJustMove, player, skel.name)
      end
    end
    room:cleanProcessingArea(cards, skel.name)
  end,
})

skel:addEffect(fk.Damaged, {
  anim_type = "masochism",
  audio_index = 2,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name) and target == player
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askToSkillInvoke(player, { skill_name = skel.name, prompt = "#rmt__xuanjian-nondamage" })
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local cards = room:getNCards(3)
    room:moveCardTo(cards, Card.Processing, nil, fk.ReasonJustMove, skel.name, nil, true, player)
    room:delay(800)
    if not player.dead then
      local get = table.filter(cards, function (id)
        return room:getCardArea(id) == Card.Processing and not Fk:getCardById(id).is_damage_card
      end)
      if #get > 0 then
        room:obtainCard(player, get, true, fk.ReasonJustMove, player, skel.name)
      end
    end
    room:cleanProcessingArea(cards, skel.name)
  end,
})

return skel
